package util.boyaa.processManager 
{
	
	/**
	 * 并行的操作任务
	 * @author henrylee   Any question, pls contact me. henrylee_sz@qq.com.
	 */
	public class ParallelProcess extends AbstractProcessPackage
	{
		/** 单一职能 */
		protected var key:String;
		/** 任务需要时间长度（以秒为单位） */
		protected var duration:Number;
		/** 操作时间间隔 */
		protected var OFFSET: Number;
		
		public function ParallelProcess() 
		{
			super();
		}
		
		/**
		 * 重写该函数
		 * 填写处理过程能识别的任务
		 * 该基类实现单一职能，只解析一种数据格式
		 */
		//protected function initAbility():void
		//{
			// For example
			//key = "comattack";
			//duration = 2.4;
			//OFFSET = 0.4;
		//}
		
		
		override public function doAI(aiData:Object, doneFunc:Function = null):void
		{
			_aiData = aiData;
			isRunning = true;
			onDoneFunc = doneFunc;
			
			var timeoffset:Number = 0;
			var taskList: Array = _aiData as Array;
			var len: int = taskList == null ? 0 : taskList.length;
			var singleData: Object;
			var i: int;
			while (i < len) {
				singleData = taskList[i];
				if (singleData.hasOwnProperty(key)) {
					delayCall(timeoffset, doProcess, [singleData]);
					timeoffset += OFFSET;
				}
				i++;
			}
			
			delayCall(duration, doneProcess);
		}
		
		
	}

}